import ky from 'ky'

interface httpResponse {
  status?: string
  url?: unknown
  exported_items?: string
}

export async function uploadData(data: unknown, apiUrl: string, apiKey: string) {
  if (!apiKey || !apiUrl) {
    return false
  }
  const res: httpResponse = await ky(apiUrl, {
    method: 'PUT',
    searchParams: {
      apiKey,
    },
    body: JSON.stringify(data),
    headers: {
      'content-type': 'application/json',
    },
  }).json()
  return !!res.url
}

export async function downloadData(cloudUrl: string) {
  if (!cloudUrl)
    return false
  const res: httpResponse = await ky(cloudUrl, {
    method: 'GET',
  }).json()
  return res
}
